/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 *  aion-unique is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-unique is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionemu.gameserver.network.aion.serverpackets;

import java.util.List;

import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.gameobjects.player.PlayerCommonData;
import com.aionemu.gameserver.model.gameobjects.stats.PlayerLifeStats;
import com.aionemu.gameserver.model.team.group.GroupEvent;
import com.aionemu.gameserver.model.team.group.PlayerGroup;
import com.aionemu.gameserver.network.aion.AbstractAionServerPacket;
import com.aionemu.gameserver.network.aion.GameClient;
import com.aionemu.gameserver.skillengine.model.Effect;
import com.aionemu.gameserver.world.WorldPosition;

/**
 * @author Lyahim, Lyahim, ATracer
 *
 */
public class SM_GROUP_MEMBER_INFO extends AbstractAionServerPacket<GameClient>
{
	private final PlayerGroup	group;
	private final PlayerCommonData		pcd;
	private final GroupEvent	event;

	public SM_GROUP_MEMBER_INFO(PlayerGroup group, PlayerCommonData pcd, GroupEvent event)
	{
		this.group = group;
		this.pcd = pcd;
		this.event = event;
	}

	@Override
	protected void writeImpl(GameClient client)
	{
		WorldPosition wp = pcd.getPosition();
		Player player = pcd.getPlayer();
		writeD(group.getObjectId());
		writeD(pcd.getObjectId());
		if (player != null)
		{
			PlayerLifeStats pls = player.getLifeStats();
			writeD(pls.getMaxHp());
			writeD(pls.getCurrentHp());
			writeD(pls.getMaxMp());
			writeD(pls.getCurrentMp());
			writeD(pls.getMaxFp()); //maxflighttime
			writeD(pls.getCurrentFp()); //currentflighttime
		}
		else
		{
			writeD(0);
			writeD(0);
			writeD(0);
			writeD(0);
			writeD(0); //maxflighttime
			writeD(0); //currentflighttime
		}
		writeD(wp.getMapId());
		writeD(wp.getMapId());
		writeF(wp.getX());
		writeF(wp.getY());
		writeF(wp.getZ());
		writeC(pcd.getPlayerClass().getClassId()); //class id
		writeC(pcd.getGender().getGenderId()); //gender id
		writeC(pcd.getLevel()); //level
		writeC(this.event.getId()); //something events
		writeH(wp.getInstanceId()); //channel
		switch (event)
		{
			case MOVEMENT:
			case DISCONNECTED:
			case LEAVE:
				return;
		}
		writeS(pcd.getName()); //name
		writeD(0x00); //unk

		if (player != null)
		{
			List<Effect> abnormalEffects = player.getEffectController().getAbnormalEffects();
			writeH(abnormalEffects.size()); //Abnormal effects
			for (Effect effect : abnormalEffects)
			{
				writeD(effect.getEffectorId()); //casterid
				writeH(effect.getSkillId()); //spellid
				writeC(effect.getSkillLevel()); //spell level
				writeC(effect.getTargetSlot()); //unk ?
				writeD(effect.getElapsedTime()); //estimatedtime
			}
		}
		else
			writeH(0);
		writeD(0x25F7); //unk 9719
	}
}
